/**
 * ReportGear(2011)
 */
package com.reportgear.report.model.auxiliary;

import org.dom4j.Element;

/**
 * 行属性列表
 * 
 * @version 1.0 2011-3-11
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 * 
 */
public class RowPropList extends AbstractCRPropList<RowProperty, RowType> {
	/**
	 * UID
	 */
	private static final long serialVersionUID = 4443539147792074898L;

	/**
	 * 构造函数
	 * 
	 * @param defaultValue
	 *            默认值
	 */
	public RowPropList(int defaultValue) {
		super(defaultValue, 0);
	}

	@Override
	public RowProperty createDefaultItem() {
		return new RowProperty(RowType.NORMAL, this.getDefaultValue());
	}

	@Override
	public RowType getType(int index) {
		if (index >= this.size()) {// 超过当前大小取默认值
			return RowType.NORMAL;
		} else {
			return this.get(index).getType();
		}
	}

	@Override
	public String getTypeStringShort(int index) {
		return "";
	}

	@Override
	public RowPropList clone() {
		RowPropList propList = new RowPropList(this.getDefaultValue());
		for (RowProperty t : this.getAllElements()) {
			propList.add(t.clone());
		}

		return propList;
	}

	@Override
	public void read(Element parent) {
		if (parent == null) {
			return;
		}

		Element element = parent.element("RPL");
		this.clear();

		if (element == null) {
			return;
		}

		for (Object o : element.elements("RP")) {
			RowProperty property = new RowProperty(0);
			this.add(property);

			property.read((Element) o);
		}
	}

	@Override
	public void write(Element parent) {
		Element element = parent.addElement("RPL");

		for (RowProperty property : this.getAllElements()) {
			Element prop = element.addElement("RP");
			property.write(prop);
		}
	}
}
